<?php

namespace App\Kuafu\Order\Service;


use App\Kuafu\Customer\Model\CustomerPlatformModel;
use App\Kuafu\Customer\Service\CustomerPlatformService;
use App\Support\AppletEncrypt;

class OrderUserService extends OrderBaseSplitService
{
    /**
     * 获取下单时用户的的 OpenId
     */
    public static function getCreateOrderUserOpenId(string $appletToken, string $platformId)
    {
        $unionid  = AppletEncrypt::getInstance()->getUserUnionid($appletToken);
        $customer = CustomerPlatformModel::query()->where('unionid', $unionid)->first();
        if (empty($userId) || $userId == 0) {
            $userOpenId = $customer->openId;
        } else {
            $userOpenId = CustomerPlatformService::getUserFieldByUserId($userId, $platformId, ['openid'])->openid ?? '';
        }

        return [$userOpenId, $unionid];
    }
}
